package com.wxx.config;

import javax.servlet.http.HttpSession;
import javax.websocket.HandshakeResponse;
import javax.websocket.server.HandshakeRequest;
import javax.websocket.server.ServerEndpointConfig;

/**
 * 获取HttpSession 这样ChatEndPoint类就可以操作HttpSession
 */
public class GetHttpSessionConfig extends ServerEndpointConfig.Configurator {

    @Override
    public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
        //获取HttpSession对象
        HttpSession httpSession = (HttpSession) request.getHttpSession();

        //将httpSession保存 存到ServerEndPointConfig对象中
        //在ChatEndpoint类的onOpen方法就能通过EndPointConfig对象获取在这里存入的数据
        sec.getUserProperties().put(HttpSession.class.getName(),httpSession);
    }
}
